package com.china.produce.config.rabbitmq;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.HashMap;

/**
 * @ClassName
 * @Author niujie
 * @Version
 * @Description
 * @CreateTime 2022/8/7
 */
@Configuration
public class DeadDirectConfig {

    @Bean
    public DirectExchange deadDirectExchange() {

        return new DirectExchange("direct_exchange", true, false);
    }

    @Bean
    public Queue deadDirectQueue() {

        HashMap<String, Object> args = new HashMap<>();

        args.put("x-dead-letter-exchange", "dead_direct_exchange");

        args.put("x-dead-letter-routing-key", "sms");

        return new Queue("dead.sms.direct", true, false, false, args);
    }

    @Bean
    public Binding bindQueueToDirectExchange() {

        return BindingBuilder.bind(deadDirectQueue()).to(deadDirectExchange()).with("sms.ack");
    }
}
